package bit_exercises.Day29;

import java.util.Arrays;

/**
 * @author zerorain
 * @date 2022/05/28 14:34
 **/
public class Main {
    public static void main(String[] args) {
        int[] ar = new int[]{3,2,5};
        int n = Main.getFirstUnFormedNum(ar);
        System.out.println(n);
    }
    public static int getFirstUnFormedNum(int[] arr) {
        Arrays.sort(arr);
        int min = arr[0];
        int max = 0;
        for (int value : arr) {
            max += value;
        }
        int[] arr1 = new int[max + 1];
        int ret = 0;
        for(int i = min;i <= max ; i++){
            for(int j = 0; j < arr.length - 1; j++){
                if(i == arr[j]){
                    arr1[i] = 1;
                }
                for(int k = j + 1; k < arr.length; k++){
                    if(i == arr[j] + arr[k]){
                        arr1[i] = 1;
                    }
                    if (i == arr[k]){
                        arr1[i] = 1;
                    }
                }
            }
        }
        for(int i = min ; i <= max; i ++){
            if(arr1[i] == 0){
                ret = i;
                break;
            }
        }
        if(ret == 0){
            ret = arr[arr.length - 1] + 1;
        }
        return ret;
    }
}